<?php

class lists extends Module
{
	public function index()
	{
		$results = $this->db->prepare('SELECT * FROM lists WHERE owner = ?',array($this->hash));
		$num_results = count($results);
		
		$this->res->type = 'response';
		
		$this->res->stat = 'OK';
		$this->res->data = array();
		
		if($num_results > 0)
		{
			$this->res->data = $results;
		}
	}
	public function create($title,$date,$category,$account)
	{
		$code = substr(sha1(uniqid()),0,10);
		
		$create = $this->db->prepare('INSERT INTO lists (owner,title,end_date,category,code,account) VALUES (?,?,?,?,?,?)',array($this->hash,$title,$date,$category,$code,$account),FALSE);

		$result = new StdClass;
		$result->code = $code;
		$result->id	  = $this->db->return_id();

		$this->res->type = 'response';		
		$this->res->stat = 'OK';
		$this->res->data = array($result);
		
	}
	public function update($id,$title,$date,$category)
	{
		$update = $this->db->prepare('UPDATE lists SET owner = ?,title = ?,end_date = ?,category = ? WHERE id = ?',array($this->hash,$title,$date,$category,$id),FALSE);

		$this->res->type = 'response';		
		$this->res->stat = 'OK';
		$this->res->data = array();
		
	}
	public function delete($id)
	{
		$delete = $this->db->prepare('DELETE FROM lists WHERE owner = ? AND id = ?',array($this->hash,$id),FALSE);

		$this->res->type = 'response';		
		$this->res->stat = 'OK';
		$this->res->data = array();
		
	}
	public function subscribe($id)
	{
		$create = $this->db->prepare('INSERT INTO rel_lists (user,list) VALUES (?,?)',array($this->hash,$id),FALSE);
		
		$this->res->type = 'response';		
		$this->res->stat = 'OK';
		$this->res->data = array();
	}
	public function unsubscribe($id)
	{
		$delete = $this->db->prepare('DELETE FROM rel_lists WHERE user = ? AND list = ?',array($this->hash,$id),FALSE);

		$this->res->type = 'response';		
		$this->res->stat = 'OK';
		$this->res->data = array();
	}
}


?>